
<{include file="app/header.tpl"}>

<script>
$(document).ready(function () {

    $('select').each(function () {
        var vid = $(this).attr('value');
        if (vid > 0)
        {
            $(this).val($(this).attr('value'));
        }

        if (this.options.length > 0)
            $(this).parent().show();
        else
            $(this).parent().hide();
    });


});

function formaddr_select_onchange (item)
{
    url   = $(item).attr('url');
    child = $(item).attr('child');
    value = $(item).val();

    $.post(url, {'value':value}, function (o) {
        if (o.status == 0)
        {
            sel = $('select[name='+child+']').get(0);
            $(sel).html(o.html)
            $(sel).parent().show();
        }
    }, 'json');
}

function submit_address(){
    if (!$('.userName').val()) {
        alert('请输入收货人姓名');
        return false;
    }
    var mobileNumberReg = /^(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/,
        oNumVal = $('.number').val();
    if (!mobileNumberReg.test(oNumVal)) {
         alert('请输入正确的手机号码');
         return false;
    }
    var zipCodeReg = /^[0-9]\d{5}$/,
        oZipCodeVal = $('.postalCode').val();
    if (!zipCodeReg.test(oZipCodeVal)) {
        alert('请输入正确的邮编');
        return false;
    }
    var oProvinceVal = $('.province').val();
    if (oProvinceVal === '0') {
        alert('请选择省市区');
        return false;
   }
    var oCityId = $('.cityId').val();
    if (oCityId === '0') {
        alert('请选择城市');
        return false;
   }
    var oCountryId = $('.countryId').val();
    if (oCountryId === '0') {
        alert('请选择区县');
        return false;
   }
    var oDetailInfo = $('.detailInfo').val();
    if (!oDetailInfo) {
        alert("请输入详细地址");
        return false;
    }
}
function enter_submit_address(){
    submit_address();
}

</script>

<form class="user-address-edit"  action="" method="POST" onsubmit="return enter_submit_address();">
        <p class="line"><label>收货人姓名：</label><input class="userName" required type="text" name="userName" value="<{$address.userName}>"></p>
        <p class="line"><label>手机号码：</label><input class="number" required  type="text" name="telNumber" value="<{$address.telNumber}>"></p>
        <p class="line"><label>邮政编码：</label><input class="postalCode" required type="text" name="postalCode" value="<{$address.postalCode}>"></p>
        <p class="line"><label>选择省/市/区</label><select class="province" name="proviceId" child="cityId" url="/api/region/options" value="<{$address.proviceId}>" onChange="formaddr_select_onchange(this)">
            <{foreach from=$optionsProvice item="opt"}>
                <option value="<{$opt.id}>"><{$opt.name}></option>
            <{/foreach}>
            </select></p>
        <p class="line"><label>城市：</label><select class="cityId" name="cityId" child="countryId" url="/api/region/options" value="<{$address.cityId}>" onChange="formaddr_select_onchange(this)">
            <{foreach from=$optionsCity item="opt"}>
                <option value="<{$opt.id}>"><{$opt.name}></option>
            <{/foreach}>
            </select></p>
        <p class="line"><label>区/县：</label><select class="countryId" name="countryId" value="<{$address.countryId}>">
            <{foreach from=$optionsCountry item="opt"}>
                <option value="<{$opt.id}>"><{$opt.name}></option>
            <{/foreach}>
            </select></p>
        <p class="line"><label>详细地址：</label><input class="detailInfo" required type="text" name="detailInfo" value="<{$address.detailInfo}>"></p>

        <input class="submit" type="submit" name="submit_op" onclick="return submit_address();" value="保存当前地址">
        <input type="hidden" name="refer" value="<{$refer}>">
</form>

<{include file="app/footer.tpl"}>
